package demoMod.stsconsole.powers;

import demoMod.stsconsole.characters.AbstractPlayer;
import demoMod.stsconsole.core.AbstractCreature;
import demoMod.stsconsole.helpers.DamageInfo;
import demoMod.stsconsole.interfaces.DamageSubscriber;
import demoMod.stsconsole.interfaces.TurnStartSubscriber;
import demoMod.stsconsole.monsters.AbstractMonster;

public class WeakPower extends AbstractPower implements DamageSubscriber, TurnStartSubscriber {
    public static final String ID = "WeakPower";
    public static float multi = 0.75F;

    public WeakPower(AbstractCreature owner, int amount) {
        super(ID, owner, amount);
        this.type = PowerType.DEBUFF;
    }

    @Override
    public String getUpdatedDescriptions() {
        return String.format(this.description, (int)(1.0F - (this.owner instanceof AbstractMonster ? multi : 0.75F)) * 100, this.amount[0]);
    }

    @Override
    public float onAttackToChangeDamage(float damageAmount, DamageInfo info, AbstractCreature target) {
        if (info.type == DamageInfo.DamageType.NORMAL && this.amount[0] > 0 && info.source == this.owner) {
            if (this.owner instanceof AbstractMonster) {
                return damageAmount * multi;
            } else {
                return damageAmount * 0.75F;
            }
        }
        return damageAmount;
    }

    @Override
    public void atTurnStart(boolean isPlayer) {
        if (this.owner instanceof AbstractPlayer == isPlayer) {
            this.amount[0]--;
        }
        if (this.amount[0] <= 0) {
            this.onRemove();
        }
    }

    @Override
    public int getPriority() {
        return super.getPriority() + 1;
    }
}
